package com.ruoyi.buss.report.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.buss.utils.DateUtilss;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.buss.report.mapper.ReportXdzxsxLsbMapper;
import com.ruoyi.buss.report.domain.ReportXdzxsxLsb;
import com.ruoyi.buss.report.service.IReportXdzxsxLsbService;

/**
 * 整村授信签约率、用信率-4、5Service业务层处理
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Service
public class ReportXdzxsxLsbServiceImpl implements IReportXdzxsxLsbService 
{
    @Autowired
    private ReportXdzxsxLsbMapper reportXdzxsxLsbMapper;

    /**
     * 查询整村授信签约率、用信率-4、5
     * 
     * @param sjrq 整村授信签约率、用信率-4、5ID
     * @return 整村授信签约率、用信率-4、5
     */
    @Override
    public ReportXdzxsxLsb selectReportXdzxsxLsbById(String sjrq)
    {
        return reportXdzxsxLsbMapper.selectReportXdzxsxLsbById(sjrq);
    }

    /**
     * 查询整村授信签约率、用信率-4、5列表
     * 
     * @param reportXdzxsxLsb 整村授信签约率、用信率-4、5
     * @return 整村授信签约率、用信率-4、5
     */
    @Override
    public List<ReportXdzxsxLsb> selectReportXdzxsxLsbList(ReportXdzxsxLsb reportXdzxsxLsb)
    {
        return reportXdzxsxLsbMapper.selectReportXdzxsxLsbList(reportXdzxsxLsb);
    }

    /**
     * 新增整村授信签约率、用信率-4、5
     * 
     * @param reportXdzxsxLsb 整村授信签约率、用信率-4、5
     * @return 结果
     */
    @Override
    public int insertReportXdzxsxLsb(ReportXdzxsxLsb reportXdzxsxLsb)
    {
        return reportXdzxsxLsbMapper.insertReportXdzxsxLsb(reportXdzxsxLsb);
    }

    /**
     * 修改整村授信签约率、用信率-4、5
     * 
     * @param reportXdzxsxLsb 整村授信签约率、用信率-4、5
     * @return 结果
     */
    @Override
    public int updateReportXdzxsxLsb(ReportXdzxsxLsb reportXdzxsxLsb)
    {
        return reportXdzxsxLsbMapper.updateReportXdzxsxLsb(reportXdzxsxLsb);
    }

    /**
     * 批量删除整村授信签约率、用信率-4、5
     * 
     * @param sjrqs 需要删除的整村授信签约率、用信率-4、5ID
     * @return 结果
     */
    @Override
    public int deleteReportXdzxsxLsbByIds(String[] sjrqs)
    {
        return reportXdzxsxLsbMapper.deleteReportXdzxsxLsbByIds(sjrqs);
    }

    /**
     * 删除整村授信签约率、用信率-4、5信息
     * 
     * @param sjrq 整村授信签约率、用信率-4、5ID
     * @return 结果
     */
    @Override
    public int deleteReportXdzxsxLsbById(String sjrq)
    {
        return reportXdzxsxLsbMapper.deleteReportXdzxsxLsbById(sjrq);
    }

    @Override
    public List<ReportXdzxsxLsb> jtsxqyl(ReportXdzxsxLsb reportXdzxsxLsb, LoginUser userInfo) {
        List<ReportXdzxsxLsb> doList = new ArrayList<ReportXdzxsxLsb>();
 
        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportXdzxsxLsb.getSjrq())) {
            if ("9999".equals(reportXdzxsxLsb.getSjrq())) {
                reportXdzxsxLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportXdzxsxLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportXdzxsxLsb.setSjrqs(sjrqs);

        doList = reportXdzxsxLsbMapper.zcsxqyl(reportXdzxsxLsb);

        return doList;
    }

    @Override
    public List<ReportXdzxsxLsb> jtsxqylhz(ReportXdzxsxLsb reportXdzxsxLsb, LoginUser userInfo) {
        List<ReportXdzxsxLsb> doList = new ArrayList<ReportXdzxsxLsb>();

        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportXdzxsxLsb.getSjrq())) {
            if ("9999".equals(reportXdzxsxLsb.getSjrq())) {
                reportXdzxsxLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportXdzxsxLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportXdzxsxLsb.setSjrqs(sjrqs);
        doList = reportXdzxsxLsbMapper.zcsxqylhz(reportXdzxsxLsb);

        return doList;
    }
}
